
    //获取新车数据
function getNewCarData(){
    var param={}
    var city=$("#newcar_select_city span").text();
    var sort=$("#newcar_select_1").attr('value');
    var brand=$("#newcar_select_brand span").text();
    var first_pay=$("#newcar_select_2").attr('value');
    var name=$(".search_newcar span").text();
    if(city!='全国'){
        param.city=city
    }
    if(sort>0){
        param.sort=sort
    }
    if(brand!='品牌'){
        param.brand=brand
    }
    if(first_pay>0){
        param.first_pay=first_pay
    }
    if(name!="想买什么车"){
        param.name=name
    }
    param.page=newcar_page;
    var spinner = new Spinner();   
    $.ajax({
        type: "POST",
        url: webConfig.url+"/Home/Index/getNewCarData",
        data: param,
        dataType: "JSONP",
        crossDomain: true,
        beforeSend:function(){
            // $('#loadingBox').removeClass('hidden')
            // var target = document.getElementById('loadingBox');
            // spinner.spin(target)
        },
        complete:function(){
            // $('#loadingBox').addClass('hidden')
            // spinner.spin()
        },
        success: function(data){
            var new_car_A=""
            var new_car_B=""
            if(data['new_car']) {
                for(var i in data['new_car']) {
                    var name=data['new_car'][i]['name']
                    var is_promo=data['new_car'][i]['is_promo']
                    var promo_text=""
                    var promo_hidden=''
                    promo_text="极速提车"
                            
                    var details=data['new_car'][i]['details']
                    var carnum=data['new_car'][i]['carnum']
                    var guide_price=getMoneyText(data['new_car'][i]['guide_price'])
                    var jdc_price=getMoneyText(data['new_car'][i]['jdc_price'])
                    var first_pay=getMoneyText(data['new_car'][i]['first_pay'])
                    var month_pay=parseInt(data['new_car'][i]['month_pay'])
                    var url=webConfig.ossUrl+"/Image/Cars/"+data['new_car'][i]['carnum']+"/1.jpg"
                    
                    new_car_A+='<div class="newcar_card car_info newcar_info" carnum="'+carnum+'">\
                                    <a>\
                                        <div class="newcar_card_che">\
                                            <img src="'+url+'">\
                                            <span class="newcar_card_che_span">极速提车</span>\
                                        </div>\
                                        <div class="newcar_card_che_info">\
                                            <div class="newcar_card_che_info_title">\
                                                <span>'+name+' '+details+'</span>\
                                            </div>\
                                            <div class="newcar_card_che_info_title_2">\
                                                <span class="span_k">指导价'+guide_price+'</span>\
                                                <span style="color:#FE4A06;margin-left:3%;">筋斗价'+jdc_price+'</span>\
                                            </div>\
                                            <div class="newcar_card_che_info_title_3">\
                                                服务费<span>'+first_pay+'</span>月租金'+month_pay+'元\
                                            </div>\
                                            <div class="car_detail_years_first_year_contain" style="padding:0 15px 30px 15px">\
                                                <span class="car_detail_years_first_year_contain_option padding_span">送购置税</span>\
                                                <span class="car_detail_years_first_year_contain_option padding_span">送一年保险</span>\
                                                <span class="car_detail_years_first_year_contain_option padding_span">送车牌</span>\
                                            </div>\
                                        </div>\
                                    </a>\
                                </div>'

                    new_car_B+='<div class="newcar_card_B car_info newcar_info" carnum="'+carnum+'">\
                                    <a>\
                                        <div class="newcar_card_B_img">\
                                            <img src="'+url+'">\
                                        </div>\
                                        <div class="newcar_card_B_info">\
                                            <div class="newcar_card_B_info_title_1">\
                                                <span>'+name+'</span>\
                                            </div>\
                                            <div class="newcar_card_B_info_title_2">\
                                                <span>'+details+'</span>\
                                            </div>\
                                            <div class="newcar_card_B_info_title_3">\
                                                <span class="span_k">指导价'+guide_price+'</span>\
                                                <span style="color:#FE4A06;margin-left:3%;font-weight:bold;">筋斗价'+jdc_price+'</span>\
                                            </div>\
                                            <div class="newcar_card_B_info_title_4">\
                                                服务费<span>'+first_pay+'</span>月租金'+month_pay+'元\
                                            </div>\
                                        </div>\
                                    </a>\
                                    <div class="car_detail_years_first_year_contain padd_s">\
                                        <span class="car_detail_years_first_year_contain_option">送购置税</span>\
                                        <span class="car_detail_years_first_year_contain_option">送一年保险</span>\
                                        <span class="car_detail_years_first_year_contain_option">送车牌</span>\
                                    </div>\
                                </div>'
                }
                if (newcar_page==1) {
                    $('.newcar_body_content_A').empty().append(new_car_A)
                    $('.newcar_body_content_B').empty().append(new_car_B)
                }else{
                    $('.newcar_body_content_A').append(new_car_A)
                    $('.newcar_body_content_B').append(new_car_B)
                }
                if(!$('.newcar_top').hasClass('hidden')){
                    $('.newcar_top').addClass('hidden');
                }
                
            }else{
                $('.newcar_body_content_A').empty()
                $('.newcar_body_content_B').empty()
                if($('.newcar_top').hasClass('hidden')){
                    $('.newcar_top').removeClass('hidden');
                }
            }
            if(!$('.newcar_want').hasClass('hidden')){
                $('.newcar_want').addClass('hidden');
            }
            if(!$('.off_the_net').hasClass('hidden')){
                $('.off_the_net').addClass('hidden');
            }
            
            mui('.mui-scroll-wrapper').scroll({
            indicators:false
            });
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006 
            });
            mui('#newcar-list').pullRefresh().endPulldownToRefresh(); //refresh completed加载数据true为加载完毕false为未加载完毕 
            mui('#newcar-list').pullRefresh().endPullupToRefresh(); //refresh completed加载数据true为加载完毕false为未加载完毕
            if(data['maxPage'] == "0"){
                mui('#newcar-list').pullRefresh().setStopped(true)
                mui('#newcar-list').pullRefresh().disablePullupToRefresh(); 
                mui('#newcar-list').pullRefresh().scrollTo(0,0); 
            }else{
                mui('#newcar-list').pullRefresh().setStopped(false)
                if(newcar_page==1){
                    mui('#newcar-list').pullRefresh().scrollTo(0,0);
                }
                
                if (newcar_page==data['maxPage']) {
                    if($('.newcar_want').hasClass('hidden')){
                        $('.newcar_want').removeClass('hidden');
                    }
                //已下载完毕
                    mui('#newcar-list').pullRefresh().disablePullupToRefresh(); 
                }else{
                    mui('#newcar-list').pullRefresh().enablePullupToRefresh(); //refresh completed加载数据true为加载完毕false为未加载完毕 
                }
            }
            
        },
        error:function(){
            $('.newcar_body_content_A').empty()
            $('.newcar_body_content_B').empty()
            if(!$('.newcar_top').hasClass('hidden')){
                $('.newcar_top').addClass('hidden');
            } 
            if(!$('.newcar_want').hasClass('hidden')){
                $('.newcar_want').addClass('hidden');
            }
            if($('.off_the_net').hasClass('hidden')){
                $('.off_the_net').removeClass('hidden');
            }
            mui('#newcar-list').pullRefresh().endPulldownToRefresh(); //refresh completed加载数据true为加载完毕false为未加载完毕 
            mui('#newcar-list').pullRefresh().endPullupToRefresh();
            mui('#newcar-list').pullRefresh().setStopped(true)
            mui('#newcar-list').pullRefresh().disablePullupToRefresh(); 
            mui('#newcar-list').pullRefresh().scrollTo(0,0);  
        }
    })
}
function bindPull_newcar(){
    mui('#newcar-list').pullRefresh({
        container: '#newcar-list',
        down: {
            contentdown : "下拉可以刷新",//可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
            contentover : "释放立即刷新",//可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
            callback: pulldownRefresh_newcar
        },
        up: {
            contentrefresh: '正在加载...',
            callback: pullupRefresh_newcar
        }
    });
}
/**
    * 下拉刷新具体业务实现
    */
function pulldownRefresh_newcar() {
        newcar_page=1
        getNewCarData();       
}
/**
    * 上拉加载具体业务实现
    */
function pullupRefresh_newcar() {
    newcar_page+=1;
    getNewCarData(); 
}
function resetNewCarSelect(){
    $('.newcar_header_hidden_1_option:eq(0)').siblings().removeClass("active");
    $('.newcar_header_hidden_1_option:eq(0)').addClass('active');
    $('#newcar_select_1').find('span').text("默认排序");
    $("#newcar_select_1").removeAttr('value');

    $('.hidden_first_pay_option:eq(0)').siblings().removeClass("active");
    $('.hidden_first_pay_option:eq(0)').addClass('active');
    $('#newcar_select_2').find('span').text('服务费');
    $("#newcar_select_2").removeAttr('value');
    $("#newcar_select_brand span").text("品牌");
    $("#newcar_select_city span").text("全国");
}
function bindEvent_newcar(e){
    $(".newcar_header_icon").click(function () {
        if($(".newcar_body_content_A").is('.show')){
            $(".a_new_car img").attr("src","images/1300.png");
            $(".newcar_body_content_A").addClass("hide").removeClass("show");
            $(".newcar_body_content_B").addClass("show").removeClass("hide");
        }else if($(".newcar_body_content_B").is('.show')){
            $(".a_new_car img").attr("src","images/new_car.png");
            $(".newcar_body_content_A").addClass("show").removeClass("hide");
            $(".newcar_body_content_B").addClass("hide").removeClass("show");
        }
        mui('#newcar-list').pullRefresh().scrollTo(0,0)                                                  
    });
    //默认排序
    $("#newcar_select_1").click(function (e) {
        $("#newcar_select_1 i").toggleClass("fa-caret-down");
        $("#newcar_select_1 i").toggleClass("fa-caret-up");
        $(this).toggleClass("active");
        $(".newcar_header_hidden_1").slideToggle();
        $(".newcar_header_hidden_2").slideUp();
        $("#newcar_select_2").removeClass("active");
        $("#newcar_select_2 a").removeClass("active");
        $("#newcar_select_2 i").addClass("fa-caret-down");
        $("#newcar_select_2 i").removeClass("fa-caret-up");
        $(".index_footer").toggleClass("gray_bg2");
        $(".newcar_body_content").toggleClass("gray_bg");
        if($(this).hasClass("active")){
            $('#loadingBox').removeClass('hidden');
        }else{
            $('#loadingBox').addClass('hidden');
            
        }
        e.stopPropagation();
    });
    //服务费
    $("#newcar_select_2").click(function (e) {
        $("#newcar_select_2 i").toggleClass("fa-caret-down");
        $("#newcar_select_2 i").toggleClass("fa-caret-up");
        $(this).toggleClass("active");
        $(".newcar_header_hidden_2").slideToggle();
        $(".newcar_header_hidden_1").slideUp();
        $("#newcar_select_1").removeClass("active");
        $("#newcar_select_1 a").removeClass("active");
        $("#newcar_select_1 i").addClass("fa-caret-down");
        $("#newcar_select_1 i").removeClass("fa-caret-up");
        $(".index_footer").toggleClass("gray_bg2");
        $(".newcar_body_content").toggleClass("gray_bg");
        if($(this).hasClass("active")){
            $('#loadingBox').removeClass('hidden');
        }else{
            $('#loadingBox').addClass('hidden');
        }
        e.stopPropagation();
    });

    $('#newcar_page').click(function(){
        $(".newcar_header_hidden_1").slideUp();
        $(".newcar_header_hidden_2").slideUp();
        $("#newcar_select_1 a").removeClass("active");
        $("#newcar_select_1 i").addClass("fa-caret-down");
        $("#newcar_select_1 i").removeClass("fa-caret-up");
        $("#newcar_select_2 a").removeClass("active");
        $("#newcar_select_2 i").addClass("fa-caret-down");
        $("#newcar_select_2 i").removeClass("fa-caret-up");
        $(".index_footer").removeClass("gray_bg2");
        $(".newcar_body_content").removeClass("gray_bg");
        $("#newcar_select_1").removeClass("active");
        $("#newcar_select_2").removeClass("active");

        $('#loadingBox').addClass('hidden');
    });
    $('.newcar_header_hidden_1_option').click(function(e){
        $(this).siblings().removeClass("active");
        $(this).addClass('active');
        var value=$(this).index();
        var text=$(this).find('span').text();
        $('#newcar_select_1').find('span').text(text);
        $('#newcar_select_1').attr('value',value)
        if(page_index[page_index.length-1]=="newcar_page"){
            newcar_page=1;
            getNewCarData();
        }
    })
    
    $('.hidden_first_pay_option').click(function(e){
        $(this).siblings().removeClass("active");
        $(this).addClass('active');
        var value=$(this).index();
        var text=$(this).find('span').text();
        if(text=="全部"){
            text="服务费"
        }
        $('#newcar_select_2').find('span').text(text);
        $('#newcar_select_2').attr('value',value)
        if(page_index[page_index.length-1]=="newcar_page"){
                newcar_page=1;
                getNewCarData();
        }
    })

    $("#newcar_select_brand").click(function (e) {
        if(!$('#select_brand_page').length>0){
            $("body").append(html_content.select_brand);
            bindEvent_select_brand(); 
        }
        $("#"+page_index[page_index.length-1]).hide();
        $("#select_brand_page").show();
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006 
        });
        page_index.push("select_brand_page");
    });
    
    $("#newcar_select_city").click(function (e) {
        if(!$('#select_city_page').length>0){
            $("body").append(html_content.select_city);
            bindEvent_select_city(); 
        }
        $("#"+page_index[page_index.length-1]).hide();
        $("#select_city_page").show();
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006 
        });
        page_index.push("select_city_page");
    });

    mui('body').on('tap','.newcar_info',function(e){
        this.click()
    })
    $('.refuse_newcar').click(function(e){
        newcar_page=1;
        getNewCarData();
    })
    $("body").delegate(".search_newcar","click",function(e){
        if(!$('#search_page').length>0){
            $("body").append(html_content.search);
            bindEvent_search()
        }
        $("#"+page_index[page_index.length-1]).hide();
        $("#search_page").show();
        page_index.push("search_page");
        $('body').attr('class','search_body')
        begin_search()
    })

    

}
function bindEvent_select_city(){
    var cityUrl = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js';
    $.getScript(cityUrl, function(script, textStatus, jqXHR) {
        if(remote_ip_info && remote_ip_info.city){
            $(".newcar_now_city").text(remote_ip_info.city);
        }else{
            $(".newcar_now_city").text('获取当前位置失败');
        }
    })
    $(".select_city_li").click(function (e) {
        var city=$(this).find('span').text();
        if(city=="获取当前位置失败"){
            city="全国"
        }
        $("#"+page_index[page_index.length-1]).hide();
        page_index.splice(page_index.length-1,1)
        $("#"+page_index[page_index.length-1]).show();
        $("#newcar_select_city span").text(city);
        if(page_index[page_index.length-1]=="newcar_page"){
            newcar_page=1;
            getNewCarData();
        }
    });
}

    
function bindEvent_select_brand(){
    
        $(".select_brand_li").click(function (e) {
            var brand=$(this).find('span').text();
            if(brand=="不限品牌"){
                brand="品牌"
            }
            $("#"+page_index[page_index.length-1]).hide();
            page_index.splice(page_index.length-1,1)
            $("#"+page_index[page_index.length-1]).show();
            $("#newcar_select_brand span").text(brand);
            if(page_index[page_index.length-1]=="newcar_page"){
                newcar_page=1;
                getNewCarData();
            }
    });
    
}